/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package inet.dao;

import inet.entity.Employee;
import inet.entity.ReportTimeKeeping;
import inet.entity.TimeKeeping;
import inet.entity.TimeKeepingDetail;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author MiSoKo
 */
public class demoDAO extends BaseDAO {

    //danh sánh hiển thị thông tin
    public List<ReportTimeKeeping> getAllTime() {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = null;
        List<ReportTimeKeeping> lstemp = null;
        try {
            sql = "SELECT * FROM EMPLOYEE, TIMEKEEPING WHERE TIMEKEEPING.EMP_ID = EMPLOYEE.EMP_ID";
            conn = getConnection();
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            ReportTimeKeeping emp = null;
            while (rs.next()) {
                emp = new ReportTimeKeeping();
                if (lstemp == null) {
                    lstemp = new ArrayList<ReportTimeKeeping>();
                }
                int i = 1;
                emp.setEmployee(new Employee(rs.getBigDecimal(i++), rs.getString(i++), rs.getString(i++),
                        rs.getString(i++), rs.getString(i++), rs.getString(i++), rs.getString(i++), rs.getDate(i++),
                        rs.getString(i++), rs.getInt(i++), rs.getString(i++), rs.getString(i++), rs.getInt(i++),
                        rs.getString(i++), rs.getString(i++), rs.getInt(i++), rs.getString(i++)));
                emp.setTimeKeeping(new TimeKeeping(rs.getBigDecimal(i++), rs.getString(i++), rs.getBigDecimal(i++), null));

                //emp.setListTimeKeepingDetail();

                lstemp.add(emp);
                System.out.println(emp.getEmployee().getEmp_id() + "-"
                        + "" + emp.getEmployee().getLast_name() + "-" + emp.getTimeKeeping().getTk_id()
                        + "-" + emp.getListTimeKeepingDetail());
            }
            return lstemp;
        } catch (Exception ex) {
            System.out.println("Error in sql: " + sql);
            ex.printStackTrace();
        } finally {
            releaseConnection(conn, ps, rs);
        }
        return null;
    }

    public static void main(String[] a) {
        demoDAO test = new demoDAO();
        test.getAllTime();
    }
}
